Skip to content

Commit

Permalink
Fix #633: Application still using System language on some strings
Browse files Browse the repository at this point in the history
The problem was with IconController class initialized too early.
  • Loading branch information
morevnaproject committed Apr 6, 2015
1 parent dfba4f2 commit 4675f33
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 49 deletions.
85 changes: 66 additions & 19 deletions synfig-studio/src/gui/app.cpp
Expand Up @@ -619,11 +619,6 @@ class Preferences : public synfigapp::Settings
value=strprintf("%i", (int)App::enable_mainwin_menubar);
return true;
}
if(key == "ui_language")
{
value = strprintf ("%s", App::ui_language.c_str());
return true;
}
}
catch(...)
{
Expand Down Expand Up @@ -779,11 +774,6 @@ class Preferences : public synfigapp::Settings
App::enable_mainwin_menubar = i;
return true;
}
if(key == "ui_language")
{
App::ui_language = value;
return true;
}
}
catch(...)
{
Expand Down Expand Up @@ -1332,6 +1322,32 @@ App::App(const synfig::String& basepath, int *argc, char ***argv):

app_base_path_=etl::dirname(basepath);

// Set ui language
load_language_settings();
if (ui_language != "os_LANG")
{
Glib::setenv ("LANGUAGE", App::ui_language.c_str(), 1);
}

std::string path_to_icons;
#ifdef WIN32
path_to_icons=basepath+ETL_DIRECTORY_SEPARATOR+".."+ETL_DIRECTORY_SEPARATOR+IMAGE_DIR;
#else
path_to_icons=IMAGE_DIR;
#endif
char* synfig_root=getenv("SYNFIG_ROOT");
if(synfig_root) {
path_to_icons=synfig_root;
path_to_icons+=ETL_DIRECTORY_SEPARATOR;
path_to_icons+="share";
path_to_icons+=ETL_DIRECTORY_SEPARATOR;
path_to_icons+="pixmaps";
path_to_icons+=ETL_DIRECTORY_SEPARATOR;
path_to_icons+="synfigstudio";
}
path_to_icons+=ETL_DIRECTORY_SEPARATOR;
init_icons(path_to_icons);

ui_interface_=new GlobalUIInterface();

// don't call thread_init() if threads are already initialized
Expand Down Expand Up @@ -1377,7 +1393,7 @@ App::App(const synfig::String& basepath, int *argc, char ***argv):
shutdown_in_progress=false;
SuperCallback synfig_init_cb(splash_screen.get_callback(),0,9000,10000);
SuperCallback studio_init_cb(splash_screen.get_callback(),9000,10000,10000);

// Initialize the Synfig library
try { synfigapp_main=etl::smart_ptr<synfigapp::Main>(new synfigapp::Main(basepath,&synfig_init_cb)); }
catch(std::runtime_error x)
Expand All @@ -1390,7 +1406,7 @@ App::App(const synfig::String& basepath, int *argc, char ***argv):
get_ui_interface()->error(_("Failed to initialize synfig!"));
throw;
}


// add the preferences to the settings
synfigapp::Main::settings().add_domain(&_preferences,"pref");
Expand All @@ -1400,13 +1416,6 @@ App::App(const synfig::String& basepath, int *argc, char ***argv):
// Try to load settings early to get access to some important
// values, like "enable_experimental_features".
studio_init_cb.task(_("Loading Basic Settings..."));

// Set ui language
load_settings("pref.ui_language");
if (ui_language != "os_LANG")
{
Glib::setenv ("LANGUAGE", App::ui_language.c_str(), 1);
}

load_settings("pref.use_dark_theme");
App::apply_gtk_settings(App::use_dark_theme);
Expand Down Expand Up @@ -1857,6 +1866,18 @@ App::save_settings()
std::string filename=get_config_file("accelrc");
Gtk::AccelMap::save(filename);
}
{
std::string filename=get_config_file("language");

std::ofstream file(filename.c_str());

if(!file)
{
synfig::warning("Unable to save %s",filename.c_str());
} else {
file<<App::ui_language.c_str()<<endl;
}
}
do{
std::string filename=get_config_file("recentfiles");

Expand Down Expand Up @@ -1944,6 +1965,32 @@ App::load_file_window_size()
}
}

void
App::load_language_settings()
{
try
{
synfig::ChangeLocale change_locale(LC_NUMERIC, "C");
{
std::string filename=get_config_file("language");
std::ifstream file(filename.c_str());

while(file)
{
std::string language;
getline(file,language);
if(!language.empty())
App::ui_language=language;
}
}

}
catch(...)
{
synfig::warning("Caught exception when attempting to loading language settings.");
}
}

void
App::set_workspace_default()
{
Expand Down
1 change: 1 addition & 0 deletions synfig-studio/src/gui/app.h
Expand Up @@ -317,6 +317,7 @@ class App : public Gtk::Main, private IconController
static bool load_settings(const synfig::String& key_filter = "");
static void load_accel_map();
static void load_file_window_size();
static void load_language_settings();
static void set_workspace_default();
static void set_workspace_compositing();
static void set_workspace_animating();
Expand Down
48 changes: 18 additions & 30 deletions synfig-studio/src/gui/iconcontroller.cpp
Expand Up @@ -83,31 +83,28 @@ IconController::IconController(const synfig::String& basepath)
IconController::IconController(const synfig::String& /*basepath*/)
#endif
{
Gtk::IconSource icon_source;
icon_source.set_direction_wildcarded();
icon_source.set_state_wildcarded();
icon_source.set_size_wildcarded();

icon_factory=Gtk::IconFactory::create();
}

std::string path_to_icons;
#ifdef WIN32
path_to_icons=basepath+ETL_DIRECTORY_SEPARATOR+".."+ETL_DIRECTORY_SEPARATOR+IMAGE_DIR;
#else
path_to_icons=IMAGE_DIR;
#endif
IconController::~IconController()
{
_tree_pixbuf_table_value_type.clear();
for(int i(0);i<((int)INTERPOLATION_CLAMPED+1);i++)
_tree_pixbuf_table_interpolation[i]=Glib::RefPtr<Gdk::Pixbuf>();

char* synfig_root=getenv("SYNFIG_ROOT");
if(synfig_root) {
path_to_icons=synfig_root;
path_to_icons+=ETL_DIRECTORY_SEPARATOR;
path_to_icons+="share";
path_to_icons+=ETL_DIRECTORY_SEPARATOR;
path_to_icons+="pixmaps";
path_to_icons+=ETL_DIRECTORY_SEPARATOR;
path_to_icons+="synfigstudio";
}
path_to_icons+=ETL_DIRECTORY_SEPARATOR;
icon_factory->remove_default();
}

void
IconController::init_icons(const synfig::String& path_to_icons)
{

Gtk::IconSource icon_source;
icon_source.set_direction_wildcarded();
icon_source.set_state_wildcarded();
icon_source.set_size_wildcarded();

try{
Gtk::Window::set_default_icon_from_file(path_to_icons+"synfig_icon."+IMAGE_EXT);
} catch(...)
Expand Down Expand Up @@ -358,15 +355,6 @@ IconController::IconController(const synfig::String& /*basepath*/)
_tree_pixbuf_table_interpolation[i]=Gtk::Button().render_icon_pixbuf(interpolation_icon(Interpolation(i)),Gtk::ICON_SIZE_SMALL_TOOLBAR);
}

IconController::~IconController()
{
_tree_pixbuf_table_value_type.clear();
for(int i(0);i<((int)INTERPOLATION_CLAMPED+1);i++)
_tree_pixbuf_table_interpolation[i]=Glib::RefPtr<Gdk::Pixbuf>();

icon_factory->remove_default();
}

Glib::RefPtr<Gdk::Cursor>
IconController::get_normal_cursor()
{
Expand Down
1 change: 1 addition & 0 deletions synfig-studio/src/gui/iconcontroller.h
Expand Up @@ -54,6 +54,7 @@ class IconController
IconController(const synfig::String& basepath);
~IconController();

void init_icons(const synfig::String& path_to_icons);
static Glib::RefPtr<Gdk::Cursor> get_normal_cursor();
static Glib::RefPtr<Gdk::Cursor> get_tool_cursor(const Glib::ustring& name,const Glib::RefPtr<Gdk::Window>& window);
};
Expand Down

0 comments on commit 4675f33

Please sign in to comment.